﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Bzzb.Model;
using FreeSql;
using FreeSql.Internal.Model;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace Bzzb.Controllers
{
    public class YiChangController : BaseController
    {
        private readonly ILogger<YiChangController> _logger;
        public YiChangController(ILogger<YiChangController> logger, IWebHostEnvironment env, IFreeSql fsql) : base(fsql)
        {
            this._logger = logger;
        }

        [HttpPost]
        public async Task<IDictionary<string, Object>> Index()
        {
            YiChang yichang = await _fsql.Select<YiChang>().OrderBy("id desc").Limit(1).ToOneAsync();
            return RenderJson(data: yichang);
        }

        [HttpPost]
        public async Task<IDictionary<string, Object>> Save([FromForm] YiChang yichang)
        {
            long id = await _fsql.Insert(yichang).ExecuteIdentityAsync();
            yichang.Id = id;
            return RenderJson(data: yichang);
        }
    }
}
